package com.lp.business.dao;

import java.util.List;

import org.iframework.commons.domain.order.Order;
import org.iframework.commons.domain.pager.Pager;
import org.iframework.commons.util.fast.D;
import org.iframework.commons.util.fast.V;
import org.iframework.support.spring.hibernate.dao.BaseHibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.lp.business.model.Role;

/**
 * 角色数据访问实现类
 * 
 * @author lp
 * 
 */
@Repository("roleDao")
public class RoleDao extends BaseHibernateDaoSupport<Role, String> {

	@Override
	public List<Role> findByModel(Role model, Order order, Pager pager) {
		model = model == null ? new Role() : model;
		StringBuilder hql = new StringBuilder();
		hql.append("from Role c where 1=1");
		hql.append(V.isNotEmpty(model.getId()) ? " and c.id=:id " : "");
		hql.append(V.isNotEmpty(model.getRoleName()) ? " and c.roleName like '%" + model.getRoleName() + "%' " : "");
		hql.append(V.isNotEmpty(model.getRoleId()) ? " and c.roleId=:roleId " : "");
		hql.append(V.isNotEmpty(model.getLevel()) ? " and c.level=:level " : "");

		hql.append(V.isNotEmpty(model.getStatus()) ? " and c.status=:status " : "");
		hql.append(V.isNotEmpty(model.getRemark()) ? " and c.remark like '%"+model.getRemark()+"%' " : "");
		hql.append(V.isNotEmpty(model.getDateStart()) ? " and c.createTime>'"+D.format(model.getDateStart(), "yyyy-MM-dd HH:mm:ss")+"'" : "");
		hql.append(V.isNotEmpty(model.getDateEnd()) ? " and c.createTime<'"+D.format(model.getDateEnd(), "yyyy-MM-dd HH:mm:ss")+"'" : "");
		
		hql.append(order != null ? order.toString() : "");
		return this.findByQueryString(hql.toString(), model, pager);
	}

}
